<?php

namespace App\Models;

use Encore\Admin\Facades\Admin;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Shop extends Model
{
//	use SoftDeletes;

	// 1:直营 2:连锁 3:加盟
	const DIRECT = 1;
	const CHAIN  = 2;
	const JOIN   = 3;
	const GENRES = [
		self::DIRECT => '直营',
		self::CHAIN  => '连锁',
		self::JOIN   => '加盟',
	];

	protected $appends = ['prov_name'];

	/*protected $appends = ['prov_id', 'city_id', 'prov_name'];

	public function getProvIdAttribute()
	{
		return $this->dist_id ? intval(substr($this->dist_id, 0, 2) . '0000') : 0;
	}

	public function getCityIdAttribute()
	{
		return $this->dist_id ? intval(substr($this->dist_id, 0, 4) . '00') : 0;
	}*/

	public function getProvNameAttribute()
	{
		return Area::query()->where('id', $this->prov_id)->value('name') ?: '';
	}

	public function save(array $options = [])
	{
		$this->actor_id = Admin::user()->id;
		parent::save();
	}
}
